package com.qf.controller;

import com.github.pagehelper.PageInfo;
import com.qf.pojo.Car;
import com.qf.service.CarService;
import com.qf.vo.CarList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class CarController {
    @Autowired
    private CarService carService;

    @GetMapping("/carlist")
    public PageInfo<Car> findAll(@RequestParam("page")int page){
        return carService.findAll (page);
    }

    @GetMapping("car{cid}")
    public CarList findCityCar(@PathVariable("cid")int cid){

        return carService.findAllBy (cid);
    }

    @GetMapping("/cars{cid}")
    public Car findOneCar(@PathVariable("cid")int cid){

        return carService.findOneCar(cid);
    }

    @PostMapping("/car")
    public Car add(@RequestBody Car car){
        return carService.add (car);
    }

    @PutMapping("/car")
    public int update(@RequestBody Car car){
        System.out.println ("ccccc");
        return carService.update(car);
    }

    @DeleteMapping("/car{id}")
    public int delete(@PathVariable("id")int id){
        return carService.delete(id);
    }
}
